﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="XsdAll", Namespace="http://kis.x-road.eu/", Target=typeof(XsdAll))]
    public class XsdAllSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected XsdAll clazz;
        
        public XsdAllSerializer(XsdAll clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("XsdStringNil");
            if (clazz.XsdStringNil!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.XsdStringNil))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            if (clazz.XsdStringMinOccurs0!=null) {
                Writer.WriteStartElement("XsdStringMinOccurs0");
                Writer.WriteString(clazz.XsdStringMinOccurs0.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("XsdStringNonNil");
            if (clazz.XsdStringNonNil!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.XsdStringNonNil))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : XsdStringNonNil");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdDateTimeNil");
            if (clazz.XsdDateTimeNil!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.XsdDateTimeNil))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdDateTimeNonNil");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.XsdDateTimeNonNil))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdUnsignedIntNillable");
            if (clazz.XsdUnsignedIntNillable!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdUnsignedShort(((ushort)(clazz.XsdUnsignedIntNillable))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdUnsignedIntNonNillable");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdUnsignedShort(((ushort)(clazz.XsdUnsignedIntNonNillable))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("DegreesNonNillable");
            if (clazz.DegreesNonNillable!=null) {
                Writer.WriteString(clazz.DegreesNonNillable.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DegreesNonNillable");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("GengerNil");
            if (clazz.GengerNil!=null) {
                Writer.WriteString(clazz.GengerNil.ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "XsdStringNil")) {
                goto XsdStringNil;
            }
            else {
                if ((Reader.LocalName == "XsdStringMinOccurs0")) {
                    goto XsdStringMinOccurs0;
                }
                else {
                    if ((Reader.LocalName == "XsdStringNonNil")) {
                        goto XsdStringNonNil;
                    }
                    else {
                        if ((Reader.LocalName == "XsdDateTimeNil")) {
                            goto XsdDateTimeNil;
                        }
                        else {
                            if ((Reader.LocalName == "XsdDateTimeNonNil")) {
                                goto XsdDateTimeNonNil;
                            }
                            else {
                                if ((Reader.LocalName == "XsdUnsignedIntNillable")) {
                                    goto XsdUnsignedIntNillable;
                                }
                                else {
                                    if ((Reader.LocalName == "XsdUnsignedIntNonNillable")) {
                                        goto XsdUnsignedIntNonNillable;
                                    }
                                    else {
                                        if ((Reader.LocalName == "DegreesNonNillable")) {
                                            goto DegreesNonNillable;
                                        }
                                        else {
                                            if ((Reader.LocalName == "GengerNil")) {
                                                goto GengerNil;
                                            }
                                            else {
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        XsdStringNil:
            if ((Reader.IsElementNil() == false)) {
                clazz.XsdStringNil = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("XsdStringNil")).Value;
            }
            else {
                Reader.Skip();
            }
            goto START;
        XsdStringMinOccurs0:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdAll>XsdStringMinOccurs0");
            }
            clazz.XsdStringMinOccurs0 = new global::Kis.Xroad.Eu.Gender(Reader.ReadElementString("XsdStringMinOccurs0"));
            goto START;
        XsdStringNonNil:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdAll>XsdStringNonNil");
            }
            clazz.XsdStringNonNil = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("XsdStringNonNil")).Value;
            goto START;
        XsdDateTimeNil:
            if ((Reader.IsElementNil() == false)) {
                clazz.XsdDateTimeNil = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("XsdDateTimeNil")).Value;
            }
            else {
                Reader.Skip();
            }
            goto START;
        XsdDateTimeNonNil:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdAll>XsdDateTimeNonNil");
            }
            clazz.XsdDateTimeNonNil = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("XsdDateTimeNonNil")).Value;
            goto START;
        XsdUnsignedIntNillable:
            if ((Reader.IsElementNil() == false)) {
                clazz.XsdUnsignedIntNillable = new global::Xtee.Core.Schema.XsdUnsignedShort(Reader.ReadElementString("XsdUnsignedIntNillable")).Value;
            }
            else {
                Reader.Skip();
            }
            goto START;
        XsdUnsignedIntNonNillable:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdAll>XsdUnsignedIntNonNillable");
            }
            clazz.XsdUnsignedIntNonNillable = new global::Xtee.Core.Schema.XsdUnsignedShort(Reader.ReadElementString("XsdUnsignedIntNonNillable")).Value;
            goto START;
        DegreesNonNillable:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdAll>DegreesNonNillable");
            }
            clazz.DegreesNonNillable = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("DegreesNonNillable"));
            goto START;
        GengerNil:
            if ((Reader.IsElementNil() == false)) {
                clazz.GengerNil = new global::Kis.Xroad.Eu.Gender(Reader.ReadElementString("GengerNil"));
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
    }
}
